<?php
/*
	首页
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$member=$this->model('member')->get_member();
	$member['credit1passtime']=date('Y年m月d日',time()+7*24*3600);
	$_SESSION['sex']=$member['sex'];
	$return['setting']=$return['pluginset'];
	$return['member']=$member;
	$return['params']=array('type'=>$_RQ['type']?:3);
	$return['list']=array();
	$_SESSION['tantime']=$_SESSION['tantime']?:0;
	$return['post']=array('jy'=>'');
	//$_SESSION['tantime']=0;
	if($_SESSION['tantime']<time()-1800){
		if($this->setting['open_tanimg']==2 || $this->setting['open_tanimg']==3){
			$return['tanfans']=$this->model('member')->get_tanfans();
			foreach($return['tanfans'] as &$tv){
				$tv['selected']=1;
			}
		}else{
			
		}
		$_SESSION['tantime']=time();
	}else{
		$return['noshowtanimg']=true;
	}
	$return['sex']=$this->sex;
	$return['sex'][0]='不限';
	$return['xuelis']=$this->xuelis2;
	$return['shourus']=$this->shourus;
	$return['years']=$this->years;
	$return['tixing']=$this->tixing;
	$return['pcd']=$this->session('pcd')?:array('city'=>'');
	$sharelink='jy_ailiao/list//type='.$_RQ['type'].'&fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
			'title'=>$return['pluginset']['share_title']?:'发现列表',
			'desc'=>$return['pluginset']['share_desc']?:'发现列表，成就天下姻缘！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>tomedia($return['pluginset']['share_image'])
	);
	set_html('title','动态列表');
	exi($return);
}
if($_RQ['op']=='uppcd'){
	$post=get_postdata();
	if(intval($post['lat'])){
		$lat_lng=array('lat'=>$post['lat'],'lng'=>$post['lng']);
		$this->session('lat_lng',$lat_lng);
	}
	$this->session('pcd',$post);
	exi('更新成功！');
}
if($_RQ['op']=='getmember'){
	$type=$_RQ['type'];
	//获取最近50家店
	if(intval($_RQ['lat'])){
		$lat_lng=array('lat'=>$_RQ['lat'],'lng'=>$_RQ['lng']);
		$this->session('lat_lng',$lat_lng);
	}
	$lat_lng=$this->session('lat_lng');
	if($type==1){
		$order='juli';
	}elseif($type==2){
		$order='islike';
	}elseif($type==6){
		$order='istuijie';
	}
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>0,
		'order'=>$order,
		'sex'=>$_SESSION['sex']==1?2:1,
	);
	if($type==3){
		$pcd=$this->session('pcd');
		if($pcd['city']){
			$params['city']=$pcd['city'];
		}
	}
	if($_RQ['keyword']){
		$params['nickname like']='%'.trim($_RQ['keyword']).'%';
	}
	if(isset($_RQ['xueli']) && $_RQ['xueli']>=0){
		$params['xueli']=$_RQ['xueli'];
	}
	if(isset($_RQ['tixing']) && $_RQ['tixing']>=0){
		$params['tixing']=$_RQ['tixing'];
	}
	if(isset($_RQ['shouru']) && $_RQ['shouru']>=0){
		$params['shouru']=$_RQ['shouru'];
	}
	if(isset($_RQ['year']) && $_RQ['year']>=0){
		$nowyear=date('Y');
		$endy=$nowyear+1-intval($this->years2[$_RQ['year']][0]);
		$starty=$nowyear+1-intval($this->years2[$_RQ['year']][1]);
		$params['year between']=array($starty,$endy);
	}
	if($_RQ['city'] && $return['pluginset']['is_city']){
		$pcd=array(
			'province'=>$_RQ['province'],
			'city'=>$_RQ['city'],
			'district'=>$_RQ['district'],
		);
		$this->session('pcd',$pcd);
		$params['city']=$_RQ['city'];
	}
	$orderby='id desc';
	$pindex = max(1, 1);
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,10000),//获取所有
		'fields'=>'',
		'key'=>'id',
		'orderby'=>$orderby,
		'orderbykey'=>$orderbykey,
	);
	$logs=$this->model('member')->getmemberlist($parameter,$_RQ['limit'],$lat_lng,intval($_RQ['page']),intval($_RQ['juli']));
	foreach($logs as $k=>&$v){
		$v['logo']=$v['logo']?tomedia($v['logo']):'';
		$v['topimg']=$v['topimg']?tomedia($v['topimg']):'';
		$v['createtime']=date('Y-m-d',$v['createtime']);
		$v['pcd']=json_decode($v['pcd'],true);
		$v['xueliinfo']=$this->xuelis2[$v['xueli']];
		if(count($v['images'])<4){
			$v['images2']=array();
			$num=4-count($v['images']);
			for($i=0;$i<$num;$i++){
				$v['images2'][]=$i;
			}
		}
	}
	$return['list']=array_values($logs);
	exi($return);
}
if($_RQ['op']=='tanset'){
	$tanfans=get_postdata();
	$msg=$tanfans[0]['msg']?:$this->setting['liao_lookmsg'];
	$msg=$msg?:'你好！可以交改朋友吗?';
	foreach($tanfans as $v){
		if($v['selected']){
			if($this->setting['open_tanimg']==3){
				$tcp=$this->model('kefu')->gettcp(0,$v['mid'],'');
				$postdata=array(
					'tcpid'=>$tcp['id'],
					'tomid'=>$v['mid'],
					'msg'=>$msg,
					'type'=>0,
				);
				$res=$this->model('kefu')->addchatlog($postdata);
			}else{
				$isadd=pdo_get('jy_ailiao_likes',array('mid'=>$_SESSION['uid'],'tomid'=>$v['mid']));
				if(!$isadd['id']){
					$data=array(
						'mid'=>$_SESSION['uid'],
						'tomid'=>$v['mid'],
						'uniacid'=>$_SESSION['uniacid'],
						'createtime'=>time(),
					);
					pdo_insert('jy_ailiao_likes',$data);
				}
			}
		}
	}
	$msg=$this->setting['open_tanimg']==2?'关注成功！':'打招呼成功';
	exi($msg);
}
?>